package com.eugene.element;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.entity.MvData;
import com.eugene.enums.EMarketVariableType;

//public class MarketVariable implements Serializable{
public  class MarketVariable implements Serializable{	
	private final static Logger logger = LoggerFactory.getLogger(MarketVariable.class);
//	private static final long serialVersionUID = 1L;
	private String mvId;
	private String mvTypeId;
	private EMarketVariableType mvTypeE;
	
//	private boolean riskFactor;
	private String riskFactorType;
	private boolean creditRf;
	private boolean marketRf;
	private boolean activeCrdGrade;
	
	private List<MvData> mvDataSet = new ArrayList<MvData>();
	private List<MvData> mvHisData = new ArrayList<MvData>();
	private Map<FnCalendar,List<MvData>> mvDataMap = new LinkedHashMap<FnCalendar, List<MvData>>();
	
	
	public Map<FnCalendar, List<MvData>> getMvDataMap() {
		
		if(mvDataMap.keySet().size()==0){
			
			for(MvData zz: mvHisData){
				
//				logger.debug("Test mvMap:{},{}", zz.getBaseDate(),zz.getMaturity());
				
				if(mvDataMap.containsKey(zz.getBaseDate())){
					List<MvData> temp = new ArrayList<MvData>();
					temp = mvDataMap.get(zz.getBaseDate());
					temp.add(zz);
					mvDataMap.put(zz.getBaseDate(),temp);
					logger.debug("Test in Map:{},{}", zz.getBaseDate(),temp.size());
				}
				else {
					List<MvData> temp = new ArrayList<MvData>();
					temp.add(zz);
					logger.debug("Test out Map:{},{}", zz.getBaseDate(),temp.size());
					mvDataMap.put(zz.getBaseDate(),temp);
				}
//				mvDataMap.put(zz.getBaseDate(),temp);
				logger.debug("Test After Map:{},{}", zz.getBaseDate(),mvDataMap.get(zz.getBaseDate()).size());
//				temp.clear();
			}
		
//			for(MvData aa: mvDataSet){
//				if(mvDataMap.containsKey(aa.getBaseDate())){
//					temp = mvDataMap.get(aa.getBaseDate());
//					temp.add(aa);
//				}
//				else {
//					temp.add(aa);
//				}
//				mvDataMap.put(aa.getBaseDate(),temp);
//				temp.clear();
//			}
		}
		return mvDataMap;
	}
	public void setMvDataMap(Map<FnCalendar, List<MvData>> mvDataMap) {
		this.mvDataMap = mvDataMap;
	}
	public List<MvData> getMvDataSet() {
		return mvDataSet;
	}
	public void setMvDataSet(List<MvData> mvDataSet) {
		this.mvDataSet = mvDataSet;
	}
	
	public EMarketVariableType getMvTypeE() {
		return mvTypeE;
	}
	public void setMvTypeE(EMarketVariableType mvTypeE) {
		this.mvTypeE = mvTypeE;
	}
	
	public String getMvId() {
		return mvId;
	}
	public void setMvId(String mvId) {
		this.mvId = mvId;
	}
	public String getMvTypeId() {
		return mvTypeId;
	}
	public void setMvTypeId(String mvTypeId) {
		this.mvTypeId = mvTypeId;
	}
	
	public String getRiskFactorType() {
		return riskFactorType;
	}
	public void setRiskFactorType(String riskFactorType) {
		this.riskFactorType = riskFactorType;
	}
//	public boolean isRiskFactor() {
//		return riskFactor;
//	}
//	public void setRiskFactor(boolean riskFactor) {
//		this.riskFactor = riskFactor;
//	}
	public boolean isCreditRf() {
		return creditRf;
	}
	public void setCreditRf(boolean creditRf) {
		this.creditRf = creditRf;
	}
	
	public boolean isMarketRf() {
		return marketRf;
	}
	public void setMarketRf(boolean marketRf) {
		this.marketRf = marketRf;
	}
	public boolean isActiveCrdGrade() {
		return activeCrdGrade;
	}
	public void setActiveCrdGrade(boolean activeCrdGrade) {
		this.activeCrdGrade = activeCrdGrade;
	}
	public List<MvData> getMvHisData() {
		if(!mvHisData.containsAll(mvDataSet)){
			mvHisData.addAll(mvDataSet);
		}
		return mvHisData;
	}
	public void setMvHisData(List<MvData> mvHisData) {
		this.mvHisData = mvHisData;
	}
	@Override
	public boolean equals(Object other){
		return super.equals(other); 
	}
	@Override
	public int hashCode(){
		return super.hashCode();
	}
//	abstract public <T extends Calculable> List<T> getMVData(FnCalendar baseDate,FnCalendar fwdDate) ;
//	abstract public <T extends Calculable> List<T> getMVData(FnCalendar baseDate) ;
	
	public List<MvData> getMvData(){
//		List<MvData> rst = new ArrayList<MvData>();
		for(MvData aa: getMvHisData()){
			aa.setMvDataId(aa.getMvId()+"_"+ aa.getMaturity());
		}
		return this.getMvHisData();
	}
	public List<MvData> getMvData(FnCalendar baseDate){
		List<MvData> rst = new ArrayList<MvData>();
		for(MvData aa: getMvHisData()){
			if(aa.getBaseDate().equals(baseDate)){
				aa.setMvDataId(aa.getMvId()+"_"+ aa.getMaturity());
				rst.add(aa);
			}
		}
		return rst;
	}
	public List<MvData> getMvData(FnCalendar baseDate,FnCalendar fwdDate){
		List<MvData> rst = new ArrayList<MvData>();
		for(MvData aa: getMvHisData()){
			if(aa.getBaseDate().equals(baseDate)){
				aa.setMvDataId(aa.getMvId()+"_"+ aa.getMaturity());
				rst.add(aa);
			}
		}
		return rst;
	}
	
}
